package com.yungu.swift.api.route.v1.driver;

import com.yungu.swift.api.base.BaseApi;
import com.yungu.swift.api.facade.DriverFacade;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.constants.CommonConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Created by cuixiuyin on 2018/4/14.
 */
@Controller
@RequestMapping(value = "/api/v1/driver")
@Api(value = "【司机】【订单】【快车】订单接口", tags = "快车司机订单相关操作")
public class DriExpressOrderApi extends BaseApi {

    @Autowired
    private DriverFacade driverFacade;


    @RequestMapping(value = {"/token/ExpressOrder/arrive"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    @ApiOperation(value = "快车司机到达目的地接口", notes = "到达目的地", response = ResponseData.class)
    public ResponseData<Boolean> arrive(
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "orderUuid", value = "订单id", required = true) @RequestParam String orderUuid,
            @ApiParam(name = "tripDistance", value = "实际行驶里程(km)", required = true) @RequestParam Double tripDistance,
            @ApiParam(name = "destAddress", value = "终点地址标题") @RequestParam(required = false) String destAddress,
            @ApiParam(name = "destDetailAddress", value = "终点的详细地址") @RequestParam(required = false) String destDetailAddress,
            @ApiParam(name = "destCity", value = "终点城市") @RequestParam(required = false) String destCity,
            @ApiParam(name = "destLng", value = "终点经度") @RequestParam(required = false) Double destLng,
            @ApiParam(name = "destLat", value = "终点纬度") @RequestParam(required = false) Double destLat,
            @ApiParam(name = "uploadText", value = "长连接上传的报文") @RequestParam(required = false) String uploadText,
            @ApiParam(name = "tripRecording", value = "行程录音") @RequestParam(required = false) String tripRecording,
            HttpServletRequest request) {
        return driverFacade.arrive(getUserUid(request), orderUuid, tripDistance, CommonConstant.BUSINESS_TYPE_EXPRESS,
                destAddress, destDetailAddress, destCity, destLng, destLat, uploadText, tripRecording);
    }


    @RequestMapping(value = {"/token/ExpressOrder/status"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    @ApiOperation(value = "快车司机首页获取订单状态", notes = "订单状态", response = ResponseData.class)
    public ResponseData<Map<String, Object>> status(HttpServletRequest request) {
        return driverFacade.status(getUserUid(request), CommonConstant.BUSINESS_TYPE_EXPRESS);
    }

}
